package org.uni_hi.muus.util;

import java.util.Calendar;
import java.util.Date;

public class DateTimeFormatter {

	private static final String[] 
	    DAY_NAMES_SHORT={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"},
		DAY_NAMES_LONG={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
	private static final String[]
	    MONTH_NAMES_SHORT={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},
	    MONTH_NAMES_LONG={"January","February","March","April","May","June","July","August","September","October","November","December"};
	
	public static String getHTTPDateNow(){
		return getHTTPDateFromCalendar(Calendar.getInstance());
	}
	
	public static String getHTTPDateFromLong(long l){
		return getHTTPDateFromDate(new Date(l));
	}
	
	public static String getHTTPDateFromDate(Date d){
		Calendar c=Calendar.getInstance();
		c.setTime(d);
		return getHTTPDateFromCalendar(c);
	}
	
	public static String getHTTPDateFromCalendar(Calendar c){
		return DAY_NAMES_SHORT[c.get(Calendar.DAY_OF_WEEK)-1]+", "+
		c.get(Calendar.DAY_OF_MONTH)+" "+MONTH_NAMES_SHORT[c.get(Calendar.MONTH)]+" "+c.get(Calendar.YEAR)+" "+
		(c.get(Calendar.HOUR_OF_DAY)<10?"0":"")+c.get(Calendar.HOUR_OF_DAY)+":"+(c.get(Calendar.MINUTE)<10?"0":"")+c.get(Calendar.MINUTE)+":"+(c.get(Calendar.SECOND)<10?"0":"")+c.get(Calendar.SECOND)+
		" GMT";
	}
}
